package com.ruoyi.web.controller.bbsAdmin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bbsAdmin.domain.vo.PlateTree;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bbsAdmin.domain.Plate;
import com.ruoyi.bbsAdmin.service.IPlateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 板块Controller
 * 
 * @author ruoyi
 * @date 2022-04-01
 */
@RestController
@RequestMapping("/bbsAdmin/plate")
public class PlateController extends BaseController
{
    @Autowired
    private IPlateService plateService;

    /**
     * 查询板块列表
     */
    @PreAuthorize("@ss.hasAnyRoles('xygly,admin')")
    @GetMapping("/list")
    @ApiOperation("获取plate接口")
    public TableDataInfo list(Plate plate)
    {
        startPage();
//        List<Plate> list = plateService.selectPlateList(plate);
        List<Plate> list = plateService.selectPlateListByRole(plate);
        //list.sort(Comparator.comparing(Plate::getCreatetime));
        return getDataTable(list);
    }


    /**
     * 查询板块列表
     */

    @GetMapping("/listPlateTree")
    @ApiOperation("获取plateTree接口")
    public List<PlateTree> list(PlateTree plateTree)
    {
        //startPage();
        List<PlateTree> list = plateService.selectPlateTree(plateTree);
        return list;
    }

    /**
     * 查询板块列表
     */


    /**
     * 导出板块列表
     */
    @PreAuthorize("@ss.hasAnyRoles('xygly,admin')")
    @Log(title = "板块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Plate plate)
    {
        List<Plate> list = plateService.selectPlateList(plate);
        ExcelUtil<Plate> util = new ExcelUtil<Plate>(Plate.class);
        util.exportExcel(response, list, "板块数据");
    }

    /**
     * 获取板块详细信息
     */
    @PreAuthorize("@ss.hasAnyRoles('xygly,admin')")
    @GetMapping(value = "/{plateid}")
    public AjaxResult getInfo(@PathVariable("plateid") String plateid)
    {
        return AjaxResult.success(plateService.selectPlateByPlateid(plateid));
    }

    /**
     * 新增板块
     */
    @PreAuthorize("@ss.hasAnyRoles('xygly,admin')")
    @Log(title = "板块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Plate plate)
    {
        return toAjax(plateService.insertPlate(plate));
    }

    /**
     * 修改板块
     */
    @PreAuthorize("@ss.hasAnyRoles('xygly,admin')")
    @Log(title = "板块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Plate plate)
    {
        return toAjax(plateService.updatePlate(plate));
    }

    /**
     * 删除板块
     */
    @PreAuthorize("@ss.hasAnyRoles('xygly,admin')")
    @Log(title = "板块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plateids}")
    public AjaxResult remove(@PathVariable String[] plateids)
    {
        return toAjax(plateService.deletePlateByPlateids(plateids));
    }



    /**
     * 查询板块列表
     */
    @GetMapping("/selectPlateListByRole")
    @ApiOperation("根据角色获取plate接口")
    public TableDataInfo selectPlateListByRole(Plate plate)
    {
        startPage();
        List<Plate> list = plateService.selectPlateListByRole(plate);
        return getDataTable(list);
    }
}
